#ifndef QP_QF_PORT_HPP
#define QP_QF_PORT_HPP

#define QP_IMPL  // this is QP implementation
#define QF_EQUEUE_TYPE QEQueue
#define QF_OS_OBJECT_TYPE pthread_cond_t
#define QF_THREAD_TYPE uint8_t

// The maximum number of active objects in the application
#define QF_MAX_ACTIVE 63
// The number of system clock tick rates
#define QF_MAX_TICK_RATE 2
// various QF object sizes configuration for this port
#define QF_EVENT_SIZ_SIZE 4
#define QF_EQUEUE_CTR_SIZE 4
#define QF_TIMEEVT_CTR_SIZE 4

#define QF_CRIT_ENTRY(dummy) QP::QF_enterCriticalSection_()
#define QF_CRIT_EXIT(dummy) QP::QF_leaveCriticalSection_()

#include <pthread.h>
#include "QEQueue.hpp"
#include "QF.hpp"

namespace QP {

void QF_enterCriticalSection_(void);
void QF_leaveCriticalSection_(void);

// set clock tick rate
void QF_setTickRate(uint32_t ticksPerSec);
// clock tick callback (provided in the app)
void QF_onClockTick(void);

extern pthread_mutex_t QF_pThreadMutex_;  // mutex for QF critical section
}

#ifdef QP_IMPL
// native event queue operations...
#define QACTIVE_EQUEUE_WAIT_(me_)               \
  while ((me_)->m_eQueue.m_frontEvt == nullptr) \
  pthread_cond_wait(&(me_)->m_osObject, &QF_pThreadMutex_)

#define QACTIVE_EQUEUE_SIGNAL_(me_)                        \
  Q_ASSERT_ID(410, QF::active_[(me_)->m_prio] != nullptr); \
  pthread_cond_signal(&(me_)->m_osObject)

#define QACTIVE_EQUEUE_ONEMPTY_(me_) ((void)0)

#endif  // QP_IMPL

#endif  // QP_QF_PORT_HPP
